<?php
$adminEmail =$_POST['admin_email'];
$adminPassword =$_POST['admin_password'];

date_default_timezone_set("PRC");  //设置时区

$dsn="mysql:Server=127.0.0.1;dbname=blog";
$db= new PDO($dsn, "root", "123456");
$db ->exec("set names utf8mb4");

$sql ="select * from admin where admin_email='{$adminEmail}'";
//echo $sql ;
$result =$db->query($sql);
$admin =$result->fetch(PDO::FETCH_ASSOC);

//if(!$admin){
//    echo "账户或密码不匹配。<a href='login.php'>前往登录页面</a>";
//    exit();
//}

if($admin['admin_password'] == $adminPassword ){
    session_start();
    $_SESSION['admin_email'] = $adminEmail;
    $_SESSION['admin_name'] = $admin['admin_name'];

    echo "登录成功。<a href='article_list.php'>前往文章页面</a>";
    exit();
}else{
    echo "登录失败，账户或密码不匹配。<a href='login.php'></a>";
    exit();
}